package com.ly.work.practice;

//奇数线程
public class OddThread extends Thread {



    @Override
    public void run() {

        synchronized (Main01.class) {
            //初始条件
            while (Main01.i<=100){
                //判断奇偶数
                if (Main01.i%2!=0){
                    //输出结果
                    System.out.println(Thread.currentThread().getName()+"==奇数=="+Main01.i);
                    Main01.i++;
                    try {
                        //唤醒线程
                        Main01.class.notify();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }else {
                    try {
                        //冻结线程
                        Main01.class.wait();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
